﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Webcam.Image
{
    public class EdgeDetection
    {
        /// <summary>
        /// The set of actions to achieve this effect
        /// </summary>
        private Filters.ImageActionSet actions = null; 

        /// <summary>
        /// Edge Tracker object
        /// </summary>
        Filters.EdgeTracker edgetracker = null;

        /// <summary>
        /// Create the EdgeDetection Set
        /// </summary>
        /// <param name="src">The image to perform edge detection on</param>
        public EdgeDetection(RGBImage src)
        {
            actions = new Filters.ImageActionSet(src);

            actions.Add(new Filters.BoxBlur(null));
            actions.Add(new Filters.MedianFilter(null));
            actions.Add(new Filters.Sobel(null));

            edgetracker = new Filters.EdgeTracker(null);
            actions.Add(edgetracker);
        }

        /// <summary>
        /// Process the image
        /// </summary>
        public void Process()
        {
            _processed = true;
            actions.Process();
        }

        /// <summary>Is the image processed yet?</summary>
        bool _processed = false;

        /// <summary>Is this image processed yet?</summary>
        public bool Processed
        {
            get { return _processed; }
        }

        /// <summary>Get the lines from the image</summary>
        /// <exception cref="NotImplementedException">When this is called, before Process() call</exception>
        public Line[] Lines
        {
            get
            {
                if (_processed)
                {
                    return edgetracker.Lines;
                }
                else
                {
                    throw new NotImplementedException("EdgeDetection has not been processed yet");
                }
            }
        }
    }
}
